package com.github.ecbp.user.service.controller.resource;

import com.github.ecbp.common.req.BaseIdDTO;
import com.github.ecbp.common.req.BaseIdListDTO;
import com.github.ecbp.user.service.api.AdminApi;
import com.github.ecbp.user.service.request.FindAdminPasswordReq;
import com.github.ecbp.user.service.response.AdminRes;
import com.github.ecbp.user.service.response.RoleRes;
import com.github.ecbp.user.service.service.AdminSaveService;
import com.github.ecbp.user.service.service.AdminService;
import com.github.ecbp.user.service.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 后台用户表 前端控制器
 * </p>
 *
 * @author zj2626
 * @since 2020-03-18
 */
@RestController
public class UserApiController implements AdminApi {
    @Autowired
    private AdminService adminService;

    @Autowired
    private AdminSaveService adminSaveService;

    @Autowired
    private RoleService roleService;

    @Override
    public AdminRes adminInfo(@Validated(BaseIdDTO.NotNullId.class) @RequestBody BaseIdDTO param) {
        return adminService.getAdminInfoById(param.getId());
    }

    @Override
    public Integer findPassword(@Validated @RequestBody FindAdminPasswordReq registerReq) {
        return adminSaveService.findPassword(registerReq, registerReq.getId());
    }

    @Override
    public Integer resetPassword(@Validated @RequestBody BaseIdListDTO param) {
        return adminSaveService.resetPassword(param);
    }

    @Override
    public List<RoleRes> getRoleListByAdminId(@Validated(BaseIdDTO.NotNullId.class) @RequestBody BaseIdDTO param) {
        return roleService.getRoleListByAdminId(param.getId());
    }
}
